package com.youhong.teethcare.test;

import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.youhong.teethcare.BaseActivity;
import com.youhong.teethcare.R;

public class FragmentTestActivity extends BaseActivity implements View.OnClickListener {


    TestAFragment testAFragment = new TestAFragment();
    TestBFragment testBFragment = new TestBFragment();

    Button btn_add, btn_attach, btn_detach,
            btn_hide, btn_remove, btn_replace, btn_show;


    private void getViews() {

        btn_add = findViewById(R.id.test_btn_add);
        btn_add.setOnClickListener(this);

        btn_attach = findViewById(R.id.test_btn_attach);
        btn_attach.setOnClickListener(this);

        btn_detach = findViewById(R.id.test_btn_detach);
        btn_detach.setOnClickListener(this);

        btn_hide = findViewById(R.id.test_btn_hide);
        btn_hide.setOnClickListener(this);

        btn_remove = findViewById(R.id.test_btn_remove);
        btn_remove.setOnClickListener(this);

        btn_replace = findViewById(R.id.test_btn_replace);
        btn_replace.setOnClickListener(this);

        btn_show = findViewById(R.id.test_btn_show);
        btn_show.setOnClickListener(this);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment_test);
        getViews();

    }


    @Override
    public void onClick(View v) {


        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

        if (v == btn_add) {

            ft.add(R.id.test_fl, testAFragment);

        } else if (v == btn_attach) {

            ft.attach(testAFragment);

        } else if (v == btn_detach) {

            ft.detach(testAFragment);

        } else if (v == btn_hide) {

            ft.hide(testAFragment);

        } else if (v == btn_remove) {

            ft.remove(testAFragment);

        } else if (v == btn_replace) {
            ft.replace(R.id.test_fl, testBFragment);
        } else if (v == btn_show) {

            ft.show(testAFragment);
        }
        ft.commit();
    }
}
